package model;

import java.sql.*;

import utils.JDBCUtil;

public class User {
	private String userName;
	private String password;
	
	public User() {
		
	}
	
	public User(String userName,String password) {
		this.userName = userName;
		this.password = password;
	}
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	@Override
	public String toString() {
		return "User [userName=" + userName + ", password=" + password + "]";
	}
	
	public static boolean login(String userName,String password) {
		String sql = "select *from users where userName = ? ";
		Connection con = null;
		PreparedStatement pt = null;
		ResultSet rs = null;
		
		try {
			con = JDBCUtil.getConnection();
			pt=con.prepareStatement(sql);
			pt.setString(1, userName);
			rs=pt.executeQuery();
			if(rs.next()&&password.equals(rs.getString("password"))){
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			JDBCUtil.realeaseAll(rs, pt, con);
		}
		return false;
	}
}
